package com.hopechart.micro.common.generator.repository;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl;

import java.sql.Types;

/**
 * @author daijiang@hopechart.com
 */
public class JavaTypeResolver extends JavaTypeResolverDefaultImpl {
    @Override
    protected FullyQualifiedJavaType overrideDefaultType(IntrospectedColumn column, FullyQualifiedJavaType defaultType) {

        switch (column.getJdbcType()) {
            case Types.DECIMAL:
                return new FullyQualifiedJavaType(Integer.class.getName());
            case Types.NUMERIC:
                return new FullyQualifiedJavaType(Long.class.getName());
            case Types.BIGINT:
                return new FullyQualifiedJavaType(Long.class.getName());
            case Types.SMALLINT:
                return new FullyQualifiedJavaType(Byte.class.getName());
            default:
                return super.overrideDefaultType(column, defaultType);
        }
    }
}
